import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:easy_chat_app/commons/model/AppUserDetail.dart';
import 'package:easy_chat_app/commons/utils/HttpUtils.dart';
import 'package:logger/logger.dart';

class UserHeadPortraitUtils {
  static Logger logger = Logger();

  static String? buildUserHeadPortrait(AppUserDetail userDetail) {
    return buildUserHeadPortraitV2(userDetail.code, userDetail.headPortrait,
        userDetail.headPortraitStoreType);
  }

  static String? buildUserHeadPortraitV2(
      String? code, String? headPortrait, String? headPortraitStoreType) {
    // logger.i("user: $userDetail");
    String result = headPortrait!;
    if (headPortraitStoreType == "local") {
      // headPortraitHash 用户解决头像更新后，页面图片不刷新的问题
      var headPortraitHash = md5.convert(utf8.encode(headPortrait));
      result =
          "${HttpUtils.baseURL}/app/user/getUserHeadPortrait?code=${code}&headPortraitHash=$headPortraitHash";
    }
    // logger.i("result: $result");
    return result;
  }
}
